package com.yntx.usercenter.base.controller;

import com.yntx.usercenter.base.dto.TenantDTO;
import com.yntx.usercenter.base.dto.TenantDeleteDTO;
import com.yntx.usercenter.base.dto.TenantUpdateDTO;
import com.yntx.usercenter.base.po.Tenant;
import com.yntx.usercenter.base.service.TenantService;
import com.yntx.usercenter.common.web.ApiResult;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/tenant")
@AllArgsConstructor
public class TenantController {

    private TenantService tenantService;

    @GetMapping
    public ApiResult<Tenant> select(Long id) {
        Tenant tenant = tenantService.getById(id);
        return ApiResult.ofSuccess(tenant);
    }

    @PostMapping("/add")
    public ApiResult<Long> add(@RequestBody TenantDTO dto) {
        Long id = tenantService.addTenant(dto);
        return ApiResult.ofSuccess(id);
    }

    @PostMapping("/delete")
    public ApiResult<?> delete(@RequestBody TenantDeleteDTO dto) {
        tenantService.deleteTenant(dto);
        return ApiResult.ofSuccess();
    }

    @PostMapping("/update")
    public ApiResult<?> update(@RequestBody TenantUpdateDTO dto) {
        tenantService.updateTenant(dto);
        return ApiResult.ofSuccess();
    }


}
